package com.travel.dao.impl;

import java.util.List;
import java.util.Objects;

import com.travel.core.AbstractDao;
import com.travel.dao.IRestaurantDao;
import com.travel.entities.Restaurant;

/**
 * @author SAGITTAR
 */
public class RestaurantDaoImpl extends AbstractDao implements IRestaurantDao {

    @Override
    public List<Restaurant> getTopResturant(String loc, String orderBy, Direction direction, int limitNum) {
        if (Objects.isNull(direction)) {
            direction = Direction.DESC;
        }
        String sql = "SELECT shopName, shopUrl, adress shopAddress, '00000000' shopTell, taste shopTaste, environment shopEnvironment, service shopService ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("FROM shop ");
        sqlBuilder.append("WHERE city= ? ");
        sqlBuilder.append("ORDER BY %s %s ");
        sqlBuilder.append("LIMIT %s");
        String preparedSql = String.format(sqlBuilder.toString(), orderBy, direction, limitNum);
        return selectListByClassTypeAndSql(Restaurant.class, preparedSql, loc);
    }

    @Override
    public List<Restaurant> selectList(String orderBy, Direction direction, int start, int count) {
        String sql = "SELECT shopName, shopUrl, shopAddress, shopTell, shopLat, shopLng, shopOpenTime, shopPersonAve, shopTaste, shopEnvironment, shopService, shopStar, shopRecommendCook ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("FROM shopbaseinfo");
        sqlBuilder.append("WHERE shopPersonAve > 1 ");
        sqlBuilder.append("ORDER BY %s %s ");
        sqlBuilder.append("LIMIT %s, %s");
        String preparedSql = String.format(sqlBuilder.toString(), orderBy, direction, start, count);
        return selectListByClassTypeAndSql(Restaurant.class, preparedSql);
    }
}
